import uniqueId from '@form-create/utils/lib/unique';
import {makeOptionsRule} from "@/components/formDesigner/utils";


const label = '弹框组件';
const name = 'dialogComponent';

export default {
    icon: 'icon-divider',
    label,
    name,
    rule() {
        return {
            type: name,
            field: name+'1',
            props:{
                dialogVisible: false,
                dynamicFormId: 1,
                buttonList:[
                    {
                        name:'提交并关闭',
                        click: async function (fApi,fApiChild,dialog) {
                            console.log('提交并关闭')
                            //执行提交按键的click事件
                            await fApiChild.exec('submitButton1','click')
                            //关闭dialog
                            dialog.closeDialog()
                            //表单加载
                            const vm = fApi.el('tablePaging1');
                            await vm.loadData();
                        }
                    },
                    {
                        name:'提交',
                        click: function (fApi,fApiChild,dialog) {
                            console.log('提交')
                            fApiChild.exec('submitButton1','click')
                            const vm = fApi.el('tablePaging1');
                            vm.loadData();
                        }
                    },
                    {
                        name:'关闭',
                        click: function (fApi,fApiChild,dialog) {
                            console.log('关闭')
                            dialog.closeDialog()
                        }
                    }
                ]
            },
            on:{
            },
        };
    },
    props() {
        return [
            {
                type: 'input',
                field: 'dynamicFormId',
                title: '嵌入的动态表单ID',
                value: ''
            },
            {
                type: 'Struct',
                field: 'buttonList',
                value: [],
                title: '按钮列表',
                props: {
                    defaultValue: [],
                    validate(val) {
                        return true
                        /*if (!Array.isArray(val)) return false;
                        if (!val.length) return true;
                        return !val.some(({rule}) => {
                            return !Array.isArray(rule);
                        });*/
                    }
                }
            },

        ];
    }
};
